<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>规则定义</title>


<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<style type="text/css">

.ration_table_title{ width:100%;border-left:1px #bbcddb solid; border-top:1px #bbcddb solid; background-color:#f6f7f9;}
.ration_table_title th{ color:#343233; width:12%; text-align:right; line-height:26px; border-bottom:1px #bbcddb solid; border-right:1px #bbcddb solid;font-weight:normal; padding-right:10px;}
.ration_table_title td{ color:#343233; text-align:left; line-height:26px; border-bottom:1px #bbcddb solid; border-right:1px #bbcddb solid;   padding:5px 0 5px 10px;}
.ration_table{ width:100%;  border-left:1px #bbcddb solid; border-top:1px #bbcddb solid; background-color:#f6f7f9;font-size: 12px;}
.ration_table th{ color:#343233; width:11%; text-align:center; line-height:26px; border-bottom:1px #bbcddb solid; border-right:1px #bbcddb solid; background-color:#f6f7f9;}
.ration_table td{text-align:center; line-height:26px;border-bottom:1px #bbcddb solid; border-right:1px #bbcddb solid;}
.ration_table .table_02 td, .table_02 .content_table_1 td{padding-left: 2px;padding-right: 2px}

.input_text {
width: 250px;
}
.select_1 {
width: 250px;
}
input.fieldError {
border: 1px solid #ffb042;
background-color: #fffbf5;
}
textarea.fieldError {
border: 1px solid #ffb042;
background-color: #fffbf5;
}
label.fieldError {
line-height: 23px;
color: #ffb042;
padding-left: 6px;
}
</style>
<script type="text/javascript">
//自定义map功能
function Map(){
  this.elements = new Array();
   //获取MAP元素个数
   this.size = function() {
       return this.elements.length;
   };
   //判断MAP是否为空
   this.isEmpty = function() {
       return (this.elements.length < 1);
   };
   //删除MAP所有元素
   this.clear = function() {
       this.elements = new Array();
   };
   //向MAP中增加元素（key, value)
   this.put = function(_key, _value) {
       if(this.containsKey(_key)){
        this.remove(_key);
        this.elements.push( {
           key : _key,
           value : _value
        });
       }else{
        this.elements.push( {
           key : _key,
           value : _value
        });
       }  
   };
   //删除指定KEY的元素，成功返回True，失败返回False
   this.remove = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   this.elements.splice(i, 1);
                   return true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
   //获取指定KEY的元素值VALUE，失败返回NULL
   this.get = function(_key) {
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   return this.elements[i].value;
               }
           }
       } catch (e) {
           return false;
       }
       return false;
   };
   //判断MAP中是否含有指定KEY的元素
   this.containsKey = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   bln = true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
  //获取map的所有values
  this.values = function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].value);
       }
       return arr;
   };
  //获取map的所有keys
  this.keys= function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].key);
       }
       return arr;
   };
   //获取数组
   this.getArray= function(){
   	var arr = new Array();
   	for (var i = 0; i < this.elements.length; i++) {
           arr.push({
	            key : this.elements[i].key,
	            value : this.elements[i].value
	         });
       }
       return arr;
   };
}
//********************************************
var map=new Map();
var map1=new Map();
var arr= new Array();
var ruleId='${ruleId}'
	$(document).ready(function() {
		initpage()
	});
	
/**初始化界面*/
function initpage(){
	arr= new Array();
	$.openLoading();
	$.ajax({
		url : "ruleConfiger/editQueryRuleList",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{
			ruleId:ruleId
		},
		success : function(data) {
			$('#prodNme').val(planCode+"-"+planName);
			$('#planCodeHidden').val(planCode);
			$('#templateId_tboday').html('');
			$.closeLoading();
			var templates=data.templates;
			$('#ruleName').val(data.RULE_NAME);
			$('#partnerNo').val(data.PARTNER_NO);
			$('#prodNme').val(data.PLAN_NAME);
			$('#planCodeHidden').val(data.PLAN_NO);
			var html='';
			var specTypeInfo=data.specTypeInfo; 
			if(templates){
				if (specTypeInfo=='0') {
					var i = templates.length;
					while(i--){
						 if(templates[i].ATTRIIDBUTE_ID=='useNature'){
							 templates.splice(i,1);
						}
					}
				} else if(specTypeInfo!='0'){
					var i = templates.length;
					while(i--){
						 if(templates[i].ATTRIIDBUTE_ID=='carNature'){
							 templates.splice(i,1);
						}
					}
				}
				for (var i = 0; i < templates.length; i++) {
					arr[i]=templates[i].ATTRIIDBUTE_ID;
                    // 麻醉类型或手术类型标志，开启配置扫码保界面是否展示麻醉类型或手术类型。
                    var anesthesiaOrSurgeryFlag = false;
                    if (templates[i].ATTRIIDBUTE_ID == 'operType'||templates[i].ATTRIIDBUTE_ID == 'anesthType') {
                        anesthesiaOrSurgeryFlag = true;
                    }
					html+="<tr>";
					if(templates[i].ATTRIIDBUTE_TYPE=='input_se'||templates[i].ATTRIIDBUTE_ID=='frameNoOrPlateNo'||templates[i].ATTRIIDBUTE_ID=='schoolConfig' || anesthesiaOrSurgeryFlag){
						if(templates[i].IS_REQUIRED=='Y'){
				 			html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' checked='checked' value='#'>"
						}else{
				 			html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' value='#'>"
						}
					}else{
					 	if(templates[i].IS_REQUIRED=='Y'){
				 			html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' checked='checked' disabled='disabled' value='#'>"
					 	}else{
				 			html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' disabled='disabled' value='#'>"
					 	}
					}
					html+="<td style='text-align: center;'><input type='hidden' id='"+templates[i].ATTRIIDBUTE_ID+"_3' value='"+templates[i].ID+"'>"
				 	html+=templates[i].ATTRIBUTE_NAME+"</td>"
				 	if(templates[i].ATTRIIDBUTE_TYPE=='select'){
				 		map1.put(templates[i].ATTRIIDBUTE_ID,templates[i].BRING_VAL)
				 		if(templates[i].ATTRIIDBUTE_ID=='isAppointBenef'){//借意险'是否指定受益人'联动处理
					 		html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' class='select_1 valid' style='  width:150px;' onChange='onchangeIsAppointBenef()'>"
				 		}else if(templates[i].ATTRIIDBUTE_ID=='IsPrintBenef'){//借意险'是否打印第一受益人'联动处理
				 			html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' class='select_1 valid' style='width: 150px;' onchange='onchangeIsPrintBenef()'>"
			 			}else{
				 			html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' class='select_1 valid' style='  width: 150px;' ><option value=''>不指定</option>"
			 			}
				 		var dictNames=templates[i].DICT_NAME;
				 		for (var j = 0; j < dictNames.length; j++) {
				 			html+="<option value='"+dictNames[j].code+"'>"+dictNames[j].codeName+"</option>";
						}
				 		html+="</select></td>"
				 	}else if(templates[i].ATTRIIDBUTE_TYPE=='time'){
				 		map1.put(templates[i].ATTRIIDBUTE_ID,templates[i].BRING_VAL)
				 		map1.put(templates[i].ATTRIIDBUTE_ID+'_4',templates[i].ATTRIIDBUTE_ID_NAME)
				 		html+="<td style='text-align: center;width: 150px;' >"
				 		html+="<select id='"+templates[i].ATTRIIDBUTE_ID+"_4' class='select_1 valid' style='  width: 150px;' onchange='effDateNameChange()'><option value='0'>次日零时</option><option value='1'>固定</option><option value='2'>不控制</option></select>  "
				 		html+="<input style='width: 150px; display :none' class='input_time' readonly='readonly' id='"+templates[i].ATTRIIDBUTE_ID+"'"
				 		html+="onclick=\"showCalendar('"+templates[i].ATTRIIDBUTE_ID+"','y-mm-dd')\";></td>"
				 	}else if(templates[i].ATTRIIDBUTE_TYPE=='select_work'){
				 		map1.put(templates[i].ATTRIIDBUTE_ID,templates[i].BRING_VAL)
				 		html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' class='select_1 valid' style='  width: 150px;' ><option value=''>不指定</option>"
				 		var dictNames=templates[i].WORK_TYPE;
				 		for (var j = 0; j < dictNames.length; j++) {
				 			html+="<option value='"+dictNames[j].code+"'>"+dictNames[j].codeName+"</option>";
						}
				 		html+="</select></td>"
				 	}
				 	else if(templates[i].ATTRIIDBUTE_TYPE=='select_school'){
				 		map1.put(templates[i].ATTRIIDBUTE_ID,templates[i].BRING_VAL)
				 		html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' onchange='schoolConfigChange(1)' class='select_1 valid' style='  width: 100px;' ><option value='' selected>学校选择</option>"
				 		var schoolNames=templates[i].SCHOOL_CONFIG;
				 		for (var j = 0; j < schoolNames.length; j++) {
				 			html+="<option value='"+schoolNames[j].code+"'>"+schoolNames[j].codeName+"</option>";
						}
				 		html+="</select><select id='"+templates[i].ATTRIIDBUTE_ID+"_Grade"+"' onchange='schoolConfigChange(2)'  class='select_1 valid' style='  width: 100px;' ><option value='' selected>年级选择</option>"
				 		var gradeNames=templates[i].SCHOOLGRADE_CONFIG;
				 		if (gradeNames) {
				 			for (var j = 0; j < gradeNames.length; j++) {
					 			html+="<option value='"+gradeNames[j].CODE+"'>"+gradeNames[j].CODE_NAME+"</option>";
							}
						}
				 		html+="</select><select id='"+templates[i].ATTRIIDBUTE_ID+"_Class"+"' class='select_1 valid' style='  width: 100px;' ><option value='' selected>班级选择</option>"
				 		var classNames=templates[i].SCHOOLCLASS_CONFIG;
				 		if (classNames) {
					 		for (var j = 0; j < classNames.length; j++) {
					 			html+="<option value='"+classNames[j]+"'>"+classNames[j]+"</option>";
							}
				 		}
				 		html+="</select></td>";
				 	}
				 	else{
				 		html+="<td style='text-align: center;'><input type='text' style='width: 150px;' id='"+templates[i].ATTRIIDBUTE_ID+"' value='"+templates[i].BRING_VAL+"'></td>"
				 	}
				 	map1.put(templates[i].ATTRIIDBUTE_ID+"_2",templates[i].IS_DISABLED)
				 	html+="<td  style='text-align: center;' class='select_1' ><select id='"+templates[i].ATTRIIDBUTE_ID+"_2' class='select_1 valid' style='  width: 150px;'><option value='Y'>是</option><option value='N'>否</option></select></td>"
				}
			}
			$('#templateId_tboday').html(html)
			if(!map1.isEmpty()){
				var keys=map1.keys();
				for (var i = 0; i < keys.length; i++) {
					if (keys[i]=="schoolConfig") {
						var array = new Array();
						array = map1.get(keys[i]).split(",");
						$('#schoolConfig').val(array[0]);
						$('#schoolConfig_Grade').val(array[1]);
						$('#schoolConfig_Class').val(array[2]);
					}else{
						$('#'+keys[i]).val(map1.get(keys[i]))
					}
				}
			}
			$('#templateId').show();
			closePlanDiv();	
			beforeLoadRule()//规则信息加载成功预处理
			onchangeIsAppointBenef();
			onchangeIsPrintBenef();
			effDateNameChange();
		}
	});
}
//规则信息加载成功预处理
function beforeLoadRule(){
	//'受益比例'规则处理
	$("#benefPercentage").val('100%');
	$("#benefPercentage").attr('disabled','disabled');
	$("#benefPercentage_2").val('N');
	$("#benefPercentage_2").attr('disabled','disabled');
}
//是否指定受益人联动处理
function onchangeIsAppointBenef(){
	var isAppointBenef=$("#isAppointBenef").val();
	if("01"==isAppointBenef){//显示受益人姓名，受益人证件类型，受益人证件号码，受益比例
		$("#benefName_1").attr('checked','checked');
		$("#benefCardType_1").attr('checked','checked');
		$("#benefCardNo_1").attr('checked','checked');
		$("#benefPercentage_1").attr('checked','checked');
		$("#benefName").removeAttr('disabled');
		$("#benefCardType").removeAttr('disabled');
		$("#benefCardNo").removeAttr('disabled');
	}else{
		$("#benefName_1").removeAttr('checked');
		$("#benefCardType_1").removeAttr('checked');
		$("#benefCardNo_1").removeAttr('checked');
		$("#benefPercentage_1").removeAttr('checked');
		$("#benefName").val('');
		$("#benefCardType").val('');
		$("#benefCardNo").val('');
		$("#benefName").attr('disabled','disabled');
		$("#benefCardType").attr('disabled','disabled');
		$("#benefCardNo").attr('disabled','disabled');
	}
}
//是否打印第一受益人联动处理
function onchangeIsPrintBenef(){
	var IsPrintBenef=$("#IsPrintBenef").val();
	if("1"==IsPrintBenef){//显示贷款网点名称
		$("#loanBankName_1").attr('checked','checked');
		$("#loanBankName").removeAttr('disabled');
	}else{
		$("#loanBankName_1").removeAttr('checked');
		$("#loanBankName").val('');
		$("#loanBankName").attr('disabled','disabled');
	}
}
function loadPlan(param){
	$.openLoading();
	$.ajax({
		url : "ruleConfiger/queryPlanList",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			var firstbutton ="<input class='input_fxk' name='radioTemple' type='radio' value=''>";
			var tableContent = creatTable1("PLAN_NO,PLAN_NAME,CODE_NAME,CHANNEL_NAME,RISK_MAIN_TYPE@TDH,PROD_TYPE@TDH,PARTNER_NO@TDH",page,firstbutton,null);
			var tableObj = $("#productTempletTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage(page.current,6,page.maxPage,"91");
			var pageDIV = $("#productTempletpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			 bindredio(); 
			$("#addPlanDiv").OpenDiv();
			
		}
	});
}
/**选择方案*/
function choosePlan(){
	var radioTemple = $("input[name='radioTemple']:checked");
	var planCode= radioTemple.parent().parent().children("td:eq(1)").html();
	var planName= radioTemple.parent().parent().children("td:eq(2)").html();
	var riskMain= radioTemple.parent().parent().children("td:eq(5)").html();
	var prodType= radioTemple.parent().parent().children("td:eq(6)").html();
	var partnerNo= radioTemple.parent().parent().children("td:eq(7)").html();
	$('#partnerNo').val(partnerNo)
	arr= new Array();
	$.openLoading();
	$.ajax({
		url : "ruleConfiger/queryTemplateList",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{
			planCode:planCode,
			riskMain:riskMain,
			prodType:prodType
		},
		success : function(data) {
			$('#prodNme').val(planCode+"-"+planName);
			$('#planCodeHidden').val(planCode);
			$('#templateId_tboday').html('');
			$.closeLoading();
			var templates=data.templates;
			var html='';
			if(templates){
				alert()
				if (specTypeInfo=='0'&&riskMain=='2') {
					var i = templates.length;
					while(i--){
						 if(templates[i].ATTRIIDBUTE_ID=='useNature'){
							 templates.splice(i,1);
						}
					}
				} else if(specTypeInfo!='0'&&riskMain=='2'){
					var i = templates.length;
					while(i--){
						 if(templates[i].ATTRIIDBUTE_ID=='carNature'){
							 templates.splice(i,1);
						}
					}
				}
				for (var i = 0; i < templates.length; i++) {
					arr[i]=templates[i].ATTRIIDBUTE_ID;
					html+="<tr>";
					if(templates[i].ATTRIIDBUTE_TYPE=='input_se'){
				 		html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' value='#'>"
					}else{
				 		html+="<td  style='text-align: center;width: 80px;' class='select_1' ><input class='input_fxk' id='"+templates[i].ATTRIIDBUTE_ID+"_1' type='checkBox' checked='checked' disabled='disabled' value='#'>"
					}
					html+="<td style='text-align: center;'><input type='hidden' id='"+templates[i].ATTRIIDBUTE_ID+"_3' value='"+templates[i].ID+"'>"
				 	html+=templates[i].ATTRIBUTE_NAME+"</td>"
				 	if(templates[i].ATTRIIDBUTE_TYPE=='select'){
				 		html+="<td style='text-align: center;'  ><select id='"+templates[i].ATTRIIDBUTE_ID+"' class='select_1 valid' style='  width: 150px;' ><option value=''>不指定</option>"
				 		var dictNames=templates[i].DICT_NAME;
				 		for (var i = 0; i < dictNames.length; i++) {
				 			html+="<option value='"+dictNames[i].code+"'>"+dictNames[i].codeName+"</option>";
						}
				 		html+="</select></td>"
				 	}
				 	else if(templates[i].ATTRIIDBUTE_TYPE=='time'){
				 		html+="<td style='text-align: center;width: 150px;' >"
				 		html+="<input style='width: 150px;' class='input_time' readonly='readonly' id='"+templates[i].ATTRIIDBUTE_ID+"'"
				 		html+="onclick=\"showCalendar('"+templates[i].ATTRIIDBUTE_ID+"','y-mm-dd')\";></td>"
				 	}
				 	else{
				 		html+="<td style='text-align: center;'><input type='text' id='"+templates[i].ATTRIIDBUTE_ID+"'></td>"
				 	}
				 	html+="<td  style='text-align: center;width: 150px;' class='select_1' ><select id='"+templates[i].ATTRIIDBUTE_ID+"_2' class='select_1 valid' style='  width: 150px;'><option value='Y'>是</option><option value='N'>否</option></select></td>"
				}
			}
			$('#templateId_tboday').html(html)
			$('#templateId').show();
			closePlanDiv();			
		}
	});
}
/***
 * 规则保存
 */
function saveRule(){
	var ruleName=$("#ruleName").val();
	var planCode=$("#planCodeHidden").val();
	var partnerNo=$("#partnerNo").val();
    var anesthType = $("#anesthType");
    var operType = $("#operType");
	if (anesthType.size() != 0) {
		if (!anesthType.parent().parent().find("td:eq(0)").find("input:eq(0)").get(0).checked && anesthType.val().length == 0) {
			$.message("error", "请选择" + $("#anesthType").parent().parent().find("td:eq(1)").text() + "默认值");
			return;
		}
	}
	if (operType.size() != 0) {
		if (!operType.parent().parent().find("td:eq(0)").find("input:eq(0)").get(0).checked && operType.val().length == 0) {
			$.message("error", "请选择" + $("#operType").parent().parent().find("td:eq(1)").text() + "默认值");
			return;
		}
	}
	if(!planCode){
		$.message("error", "方案号为空");
		return;
	}
	if(!ruleName){
		$.message("error", "规则名称为空");
		return;
	}
	if(arr){
		var arr1 = new Array(); 
		for (var i = 0; i < arr.length; i++) {
			var o=new Object();
			var attrid=$("#"+arr[i]+"_3").val();
			var attrVal=$("#"+arr[i]).val();
			var isDis=$("#"+arr[i]+"_2").val();
			var isReq='N';
			if($("#"+arr[i]+"_1").prop("checked")){
				isReq='Y';
			}
			var attrType=$("#"+arr[i]+"_4").val();
			if($("#"+arr[i]).find("option:selected").text()){
				attrType=$("#"+arr[i]).find("option:selected").text();
				if(attrType=='不指定'){
					attrType='';
				}
			};
			if (arr[i]=="schoolConfig") {
				var attrVal=$("#schoolConfig").val()
				var attrType = $("#schoolConfig option:checked").text();
				if ($("#schoolConfig_Grade").val()) {
					attrVal += ","+$("#schoolConfig_Grade").val();
					attrType += ","+$("#schoolConfig_Grade option:checked").text();
				}
				if ($("#schoolConfig_Class").val()) {
					attrVal += ","+$("#schoolConfig_Class option:checked").text();
					attrType += ","+$("#schoolConfig_Class option:checked").text();
				}
			}
			o.attrid=attrid;
			o.isDis=isDis;
			o.attrVal=attrVal;
			o.attrType=attrType;
			o.isReq=isReq;
			arr1.push(o);
		}
		var json=JSON.stringify(arr1);
		/**调用*/
		$.openLoading();
		$.ajax({
			url : "ruleConfiger/editTemplateList",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				ruleTemplate:json,
				ruleName:ruleName,
				planCode:planCode,
				partnerNo:partnerNo,
				ruleId:ruleId
			},
			success : function(data) {
				$.message(data.result, data.message);
				if(data.result=='success'){
					window.location.href='<%=path%>/ruleConfiger/list'
				}
			}
		});
	}else{
		$.message("error", "录入元素为空请联系管理员");
	}
}
/**保存规则信息*/
function bindredio(){
	$("input[name='radioTemple']").click(function(){
		$("input[name='radioTemple']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}
function queryPlan(pageCount){
	var planCode=$('#planCode').val();
	var planName=$('#planName').val();
	var partnerNo=$('#partnerNo').val();
	/* if(!$('#partnerNo').val()){
		$.message("error", "请先选中合作伙伴代码");
		return;
	} */
	loadPlan({size:6,current:pageCount,planCode:planCode,planName:planName,partnerNo:partnerNo});
}

function openPlanDiv(){
	fvreset()
	queryPlan(1);
/* 	$('#addPlanDiv').OpenDiv() */
}

function closePlanDiv(){
	$('#addPlanDiv').CloseDiv()
}
function fvreset(){
	$('#planCode').val('');
	$('#planName').val('');
}
//点击“选择(合作伙伴)”
function openChannelPageDiv(){
	queryChannelInfo(1);
}
//为查询合作伙伴 拼接参数
function queryChannelInfo(pageIndex){
	var channelCode = $.trim($('#channelCode_choose').val());
	var channelName = $.trim($('#channelName_choose').val());
	
	loadChannelInfo({current:pageIndex,size:8,channelCode:channelCode,channelName:channelName});
}
//加载合作伙伴
function loadChannelInfo(param){
	$.openLoading();
	$.ajax({
		url : "<%=path%>/nlifePlanConfig/queryChannelInfoPageByCriteria?"+new Date().getTime(),
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(page){
			$.closeLoading();
			if($.validate(page))return;

			var radioObj ="<input class='input_fxk' name='radioChannelInfo' type='radio' value=''>";
			var fieldNames = "channelCode,channelName";
			var tableContent = creatTable1(fieldNames,page,radioObj);
			var tableObj = $("#channelInfoTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage2(param.current,6,page.maxPage,"42");
			var pageDIV = $("#channelInfoPageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			$('#channelInfoDiv').OpenDiv();
			
			bindradio();
		}
	});
} 
function bindradio(){
	$("input[name='radioChannelInfo']").click(function(){
		$("input[name='radioChannelInfo']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
}
//关闭 选择合作伙伴 弹出层
function closeChannelInfoDiv(){
	$("#channelInfoDiv").CloseDiv();	
	
	$('#channelCode_choose').val("");
	$('#channelName_choose').val("");
}
//点击“确定”按钮，选择合作伙伴
function chooseChannelInfo(){
	var selected = $("input[name='radioChannelInfo']:checked");
	if(selected.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var channelCode = selected.parent().parent().children(" td:eq(1)").html();
	$('#partnerNo').val(channelCode);
	$('#prodNme').val('')
	closeChannelInfoDiv();
}


//返回录单主页面
function recancel(){
	window.location.href='<%=path%>/ruleConfiger/list';
}

function effDateNameChange(){
	var effDateType = $("#effDate_4").val();
	if (effDateType=='1') {
		$('.input_time').show();
	}else{
		$('.input_time').hide();
	}
}

function schoolConfigChange(flag) {
	if (flag==1) {
		var parentCode=$("#schoolConfig").val();
		$.ajax({
			url : "schoolConfiger/querySchoolConfigSelect",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				parentCode:parentCode
			},
			success : function(data) {
	            var gradeString = "";  
	          	for (var j = 0; j < data.length; j++) {  
	                gradeString += "<option value=\"" + data[j].CODE + "\" >" + data[j].CODE_NAME + "</option>";  
	            }  
	        	$("#schoolConfig_Grade").html("<option value=''>年级选择</option> "+gradeString);
			} 
		});
	}else if(flag==2){
		var code=$("#schoolConfig_Grade").val();
		$.ajax({
			url : "schoolConfiger/querySchoolConfigSelect",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				code:code
			},
			success : function(data) {
				var classString = "";
				var arr = new Array();
				arr = data[0].CODE_DESC.split(",");
				for (var i = 0; i < arr.length; i++) {
					classString += "<option value=\"" + data[0].CODE + "\" >" + arr[i] + "</option>";  
				}
	        	$("#schoolConfig_Class").html("<option value=''>班级选择</option> "+classString);  
			} 
		});
	}
}

</script>
<style type="text/css">
.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}

</style>
</head>
<body>
<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                       <span style=" color:#136bab; ">界面出单管理 
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>录单界面订制                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
	      
			<form id="inputForm"  >
	        <table class="table_05">
	              <tbody>
	             	<tr>
	                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">规则定义</td>
	              </tr>
	    		  <tr>
	                  <th width="25%">规则名称：</th>
	                  <td width="28%">
	                     <input name="ruleName" id="ruleName" type="text"  class="input_text"><span class="red">*</span>&nbsp;
	                   <!--   <input type="button"   id="searchBtn" value="选择模板" onClick="opentempletDiv(this)"/></td> -->
	              		<th>合作伙伴代码：</th>
	              		<td width="32%" height="30">
								<div style="display: inline-block;">
									<input name="txt3"  id="partnerNo" value="" readonly="readonly" style="background: #ccc;" class="input_text">
									<input type="button" disabled="true" class="input_button_1" id="openChannelPageDivBtn" value="选择" onClick="openChannelPageDiv()"/>
								</div>
						</td>
	              </tr>
	              <tr>
	                 <th width="20%">规则方案：</th>
	                  <td width="22%"><input id="prodNme"  type="text" readonly="true" style=" background-color: #ccc;" class="input_text"> 
	                  		<input type="button"  disabled="true" id="searchBtn" value="选择方案" onClick="openPlanDiv()"/>
	                  
	                  <input id="planCodeHidden"  type="hidden" readonly="true">
	                  </td>
	                  <th></th>
	                  <td></td>
	              </tr>
	           </tbody>
	           </table> 
	           <div style="height: 95%">
				    <table class="table_05" style="display: none;" id="templateId">
		    			<thead>
							<tr>
								<td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">规则元素定义</td>
							</tr>
							<tr style="text-align: center; font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">
								<th style="width:5%;text-align: center;">是否显示</th>
								<th style="width:15%;text-align: center;">属性名称</th>
								<th style="width:25%;text-align: center;">默认值</th>
								<th style="width:25%;text-align: center;">是否可修改</th>
							</tr>
						</thead>
						<tbody id="templateId_tboday">
						</tbody>
		           </table>
		           <span class="red" id="TipsWords">提示：学平险　'班级' 属性和 '学校/年级/班级' 属性二选一</span>
		           <div align="center">
					 <input class="input_button_3" name="" type="button" onclick="saveRule()" value="确定">&nbsp;&nbsp;
			         <input class="input_button_3" name="" type="button" onclick="recancel()" value="返回">
				   </div> 
	           </div>
	           
           </form>
		<!--   	添加模板 DIV 默认隐藏-->
  		<div id="addPlanDiv"  style="display:none;width:80%;">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path%>/images/closedown.gif" alt="关闭"  onclick="closePlanDiv()"/></td>
						</tr>
					
					</table>
			</div>
		<form id="inputForm" action="save.jhtml" method="post" enctype="multipart/form-data">
			
			<table class="table_02" id="addtempletTable" style="height:180px; " align="center" >
				<tbody>
					<tr>
						<td>
							<table class="search_table">
								<tbody>
									<tr height="30px">
										<td width="40%" height="30px">方案代码：
											<input name="txt3" id="planCode" type="text" class="input_text" value="" style="width:220px;">
										</td>
										<td width="40%" height="30px">方案名称：
											<input name="txt3" id="planName" type="text" class="input_text" value="" style="width:220px;">
										</td>
										<td width="20%" height="30px">
										   <input type="button" class="input_button_1" id="searchBtn" value="查询" onclick="queryPlan(1)">&nbsp;
										   <input type="button" class="input_button_1" id="searchBtn" value="重置" onclick="fvreset()">
										</td>
									</tr>	
								</tbody>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table id="productTempletTable"  class="content_table_1">
								<thead>
									<tr class="f1">
					                  <th style="width:5%">选择</th>
					                  <th style="width:15%">方案代码</th>
					                  <th style="width:20%">方案名称</th>
					                  <th style="width:20%">产品大类</th>
					                  <th style="width:40%">合作伙伴名称</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="productTempletpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			 <input class="input_button_3" name="" type="button" onclick="choosePlan()" value="保存">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closePlanDiv()" value="取消">
			</div>
		</form>
	</div>
	<div id="channelInfoDiv" style="display:none;width:90%;text-align: center;">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeChannelInfoDiv()"/></td>
					</tr>
				</table>
		</div>
		<table class="table_02" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
								合作伙伴代码：<input name="txt3"  id="channelCode_choose" class="input_text" />&nbsp;&nbsp;
								合作伙伴名称：<input name="txt3" id="channelName_choose" class="input_text" />&nbsp;&nbsp;
								<input type="button"  class="input_button_1" value="查询" onClick="queryChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="确定" onclick="chooseChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeChannelInfoDiv()" class="input_button_3"/>
		</div>
	</div>	
</body>
</html>